﻿@model IEnumerable<Hrm.Core.PriceType>

@{
    ViewBag.Title = "服务定价";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style>
    .item {
        margin-right: 10px;
    }
</style>
<div id="page-header" class="clearfix">
    <div class="page-header">
        <h2>服务定价</h2>
        <span class="txt">可以增删查改工作室的服务定价</span>
    </div>
</div>
<div class="panel panel-default toggle panelMove panelClose panelRefresh">
    <div class="panel-heading">
        <h4 class="panel-title">操作</h4>
    </div>
    <div class="panel-body pt0 pb0">
        <form class="form-horizontal group-border">
            @Html.AntiForgeryToken()
            <div class="form-group col-lg-6 col-md-6">
                <a class="btn btn-primary" href="@Url.Action("AddPriceType")">添加定价类型</a>
            </div>
        </form>
    </div>
</div>

<div class="panel panel-default toggle panelMove panelClose panelRefresh">
    <div class="panel-heading">
        <h4 class="panel-title">查询结果</h4>
    </div>
    <div class="panel-body">
        <table class="table table-striped table-hover dt-responsive nowrap" cellspacing="0" width="100%">
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Name)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Description)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.BelongType)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Price)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Unit)
                </th>
                <th></th>
            </tr>

            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Description)
                    </td>
                    <td>
                        @Html.HiddenFor(modelItem => item.BelongId)
                        @Html.DisplayFor(modelItem => item.BelongType)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Price)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Unit)
                    </td>
                    <td>
                        <a class="editPriceType" href="@Url.Action("UpdatePriceType", new { Id = @item.Id })">编辑</a> |
                        <a class="deletePriceType" data-pricetypeid="@item.Id">删除</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="5">
                        <span>定价选项:</span>
                        @if (item.PriceItems != null && item.PriceItems.Count > 0)
                        {
                            foreach (var subItem in item.PriceItems)
                            {
                                <span class="item">
                                    <i class="@subItem.Glyphicon"></i>
                                    @subItem.Name
                                    <i data-priceitemid="@subItem.Id" class="deletePriceItem glyphicon glyphicon-remove" style="color:red"></i>
                                </span>
                            }
                        }
                        else
                        {
                            <span>无</span>
                        }
                    </td>
                    <td>
                        <a class="addPriceItem" href="@Url.Action("AddPriceItem", new { Id = item.Id })" data-pricetypeid="@item.Id">添加定价选项</a>
                    </td>
                </tr>
            }

        </table>
    </div>
</div>
<script>
    $(document).ready(function () {
        $(".deletePriceItem").click(function () {
                var elm = this;
                $.mainTool.confirm("是否删除该信息？", function (result) {
                    $.ajax({
                        type: 'post',
                        url: '@Url.Action("DeletePriceItem")',
                        data: {
                            '__RequestVerificationToken': $("input[name='__RequestVerificationToken']").val(),
                            Id: $(elm).attr("data-priceitemid"),
                        },
                        dataType: "json",
                        success: function (data) {
                            document.location.reload();
                        },
                        error: function (e) {
                            alert(e.responseText);
                        }
                    });
                });
            });
        $(".deletePriceType").click(function () {
            var elm = this;
            $.mainTool.confirm("是否删除该信息？", function (result) {
                $.ajax({
                    type: 'post',
                    url: '@Url.Action("DeletePriceType")',
                    data: {
                        '__RequestVerificationToken': $("input[name='__RequestVerificationToken']").val(),
                        Id: $(elm).attr("data-priceTypeId"),
                    },
                    dataType: "json",
                    success: function (data) {
                        document.location.reload();
                    },
                    error: function (e) {
                        alert(e.responseText);
                    }
                });
            });
        });
    });
</script>
